package partikelTest2;

import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.Timer;

public class PartikelTest extends JFrame implements ActionListener, KeyListener{

	ParticleViewer pW = new ParticleViewer();
	
	Timer drawTimer = new Timer(1000/30, this);
	
	double speed;
	
	public PartikelTest(){
		addKeyListener(this);
	//	setLayout(new GridLayout(1,1));
		speed = 2.5;
		add(pW);
		
		drawTimer.start();
		
		setSize(400,400);
		setVisible(true);
		setDefaultCloseOperation(EXIT_ON_CLOSE);
		
	}
	
	public static void main(String[] arg){
		
		PartikelTest dPT = new PartikelTest();
		
	}

	@Override
	public void actionPerformed(ActionEvent arg0) {

		if(arg0.getSource() == drawTimer){
			
			pW.repaint();
			
		}
		
	}

	@Override
	public void keyPressed(KeyEvent arg0) {
		System.out.println(arg0.getKeyCode());
		if(arg0.getKeyCode() == 38)
			pW.rect1.rectY-=speed;
		if(arg0.getKeyCode() == 40)
			pW.rect1.rectY+=speed;
		if(arg0.getKeyCode() == 39)
			pW.rect1.rectX+=speed;
		if(arg0.getKeyCode() == 37)
			pW.rect1.rectX-=speed;
		
	}

	@Override
	public void keyReleased(KeyEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void keyTyped(KeyEvent e) {
		// TODO Auto-generated method stub
		
	}



	
}
